import subprocess
import sys
sys.path.append('../utils/')
sys.path.append('./utils/')

from mysql_connector import load_conf

def generate_data():
    """
        创建数据库并生成数据
    """
    conf = load_conf()
    warehouse = conf["warehouse"]
    host = conf["host"]
    port = conf["port"]
    user = conf["user"]
    passwd = conf["password"]
    db = conf["database"]
    
    # 导入 SQL 语句
    subprocess.call('mysql -uroot -p %s < ./tpcc_source_code/create_table.sql' % db, shell=True)
    print('导入 create_table.sql 成功!')
    subprocess.call('mysql -uroot -p %s < ./tpcc_source_code/add_fkey_idx.sql' % db, shell=True)
    print('导入 add_fkey_idx.sql 成功!')

    # 开始生成数据
    subprocess.call('./tpcc_source_code/tpcc_load %s %s %s %s %d' % (host, db, user, passwd, warehouse), shell=True)
    print('tpcc_table 数据生成完毕!')